package com.trip.order.utils;

import cn.hutool.core.lang.UUID;

import java.time.LocalDateTime;
import java.time.ZoneOffset;


public class IDWorker {
    private static final long TIME_BEGIN=946684800L;
    //位运算位数
    private static final int BIT_NUM=32;

    public static long onlyID(){
        //获取当前秒时间戳
        long currentSecond = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
        long time=currentSecond-TIME_BEGIN;
        //使用uuid
        int increment = UUID.randomUUID().variant();
        //id拼接使用序列位左移或上自增
        return time<<BIT_NUM | increment;
    }
}
